<?php
/*
 * @Author: 哲学家乔布斯 <wuyangii@qq.com>
 * @Date: 2022-10-25 20:19:21
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-10-25 20:22:43
 * @Descripttion: 
 */


namespace app\common\model;

use think\Model;

class UserOrders extends Base
{
    protected $insert = ['addtime'];
    protected $state = [
        0 => "待支付",  1 => "已支付",  2 => "待配送",  3 => "待提货",  4 => "已提货",  5 => "申请售后",
    ];
    protected $bus_state = [
        0 => "待分配",  1 => "配送中",  2 => "已完成", 
    ];
    protected $driver_state = [
        0 => "待分配",  1 => "配送中",  2 => "已完成", 
    ];

    //---------------自动完成----------------------
    protected function setAddtimeAttr()
    {
        return time();
    }
    public function getPayTimeTextAttr($value, $data){
        return date('Y-m-d H:i:s', $data['pay_time']);
    }
    public function getAddtimeTextAttr($value, $data){
        return date('Y-m-d H:i:s', $data['addtime']);
    }
    public function getStateTextAttr($value,$data){
        return $this->state[$data['state']];
    }
    public function getBusStateTextAttr($value,$data){
        return $this->bus_state[$data['bus_state']];
    }
    public function getDriverStateTextAttr($value,$data){
        return $this->driver_state[$data['driver_state']];
    }
    public function getDriverQStateTextAttr($value,$data){
        return $this->driver_state[$data['driver_q_state']];
    }
    public function getGoodsAttr($value,$data){
        return (new \app\common\model\UserOrdersGoods())
                ->field(['agent_goods_sku_id as sku_id','img'])
                ->where(['order_id' => $data['id']])->select();
    }
    public function getGoodsInfoAttr($value,$data){
        return (new \app\common\model\UserOrdersGoods())
                ->field(['agent_goods_sku_id as sku_id','img','goods_sku_title','z_money','d_money','num','goods_title'])
                ->where(['order_id' => $data['id']])->select();
    }
    public function getAgentTitleAttr($value,$data){
        return (new \app\common\model\Agent())->where(['id' => $data['agent_id']])->value('nickname');
    }
    public function getAgentAccountAttr($value,$data){
        return (new \app\common\model\Agent())->where(['id' => $data['agent_id']])->value('account');
    }
    public function getBusTitleAttr($value,$data){
        return (new \app\common\model\Bus())->where(['id' => $data['bus_id']])->value('nickname');
    }
    public function getDriverQTitleAttr($value,$data){
        return (new \app\common\model\Driver())->where(['id' => $data['driver_q_id']])->value('nickname');
    }
    public function getDriverTitleAttr($value,$data){
        return (new \app\common\model\Driver())->where(['id' => $data['driver_id']])->value('nickname');
    }
    
}
